package cn.magicduck.demo.store.impl;

import cn.magicduck.demo.store.ICommodity;
import com.alibaba.fastjson.JSON;
import demo.card.IQiYiCardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @projectName: design-pattern-demo
 * @className: CardCommodityService
 * @description: 模拟发放爱奇艺兑换卡服务
 * @author: MagicDuck
 * @create: 2020-07-16 16:24
 **/
public class CardCommodityService implements ICommodity {

    private Logger logger = LoggerFactory.getLogger(CardCommodityService.class);

    /** 模拟注入 */
    private IQiYiCardService iQiYiCardService = new IQiYiCardService();

    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        String mobile = queryUserMobile(uId);
        iQiYiCardService.grantToken(mobile, bizId);
        logger.info("请求参数[爱奇艺兑换卡] uId:{} commodityId:{} bizId:{} extMap:{}", uId, commodityId, bizId, JSON.toJSON(extMap));
        logger.info("请求结果[爱奇艺兑换卡] success");
    }

    private String queryUserMobile(String uId) {
        return "15200101232";
    }
}
